package cn.gl.basic.service.impl;

import cn.gl.basic.mapper.BaseMapper;
import cn.gl.basic.query.BaseQuery;
import cn.gl.basic.service.IBaseService;

import cn.gl.basic.util.PageList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;
    @Override
    @Transactional
    public List<T> laodAll() {
        return baseMapper.laodAll();
    }

    @Override
    public T laodOne(Long id) {
        return baseMapper.laodOne(id);
    }


    @Override
    @Transactional
    public void insert(T t) {
        baseMapper.insert(t);
    }

    @Override
    @Transactional
    public void delete(Long id) {
        baseMapper.delete(id);

    }

    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);

    }


    @Override
    @Transactional
    public PageList<T> queryPage(BaseQuery baseQuery) {
        //查询总数量
        Integer totals = baseMapper.queryCount(baseQuery);
        if (totals < 1 ){
            return new PageList<>();
        }
        //查询当前页的分页数据
        List<T> ts = baseMapper.queryData(baseQuery);
        return new PageList<>(totals,ts);
    }
    @Override
    public void patchDelete(List<Long> ids) {
        baseMapper.patchDelete(ids);
    }
}

